package com.dht.xiao.jianye.utils;

import com.licheedev.myutils.LogPlus;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * 公用抽取方法地方，简化其他地方代码
 */
public class CommonUse {
    /**
     * @return 文件转成字节数组
     */

    public static byte[] getByteArrayFromNew(String path){

        byte[] result=null;

        ByteArrayOutputStream outputStream=new ByteArrayOutputStream();

        //创建文件
        File file=new File(path + "/", "V1001_10d02256dce3db5543450ef90fdb3a11.bin");
        FileInputStream fileInputStream=null;
        try {
            fileInputStream=new FileInputStream(file);
            int len=0;
            byte[] buffer=new byte[1024];
            while((len=fileInputStream.read(buffer))!=-1){
                outputStream.write(buffer, 0, len);
            }
            result=outputStream.toByteArray();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally{
            if(fileInputStream!=null){
                try {
                    fileInputStream.close();
                    fileInputStream=null;
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }

        LogPlus.e("result长度="+result.length);
        return result;
    }
}
